<template>
  <view class="normal-login-container">
    <view class="logo-content align-center justify-center flex">
      <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
      </image>
      <text class="title">问题抢答</text>
    </view>
	
	<!-- 选择身份按钮 -->
    <view class="login-form-content">
		
		<view class="input-item flex align-center">
		  <view class="iconfont icon-user icon"></view>
		  <input v-model="userInfo.nickName" class="input" type="text" placeholder="请输入昵称" maxlength="30" />
		</view>
		
		<view class="action-btn">
			<button @click="chooseUserType('0')" class="login-btn cu-btn block bg-blue lg round">我是主持人</button>
		</view>
		<view class="action-btn">
			<button @click="chooseUserType('1')" class="login-btn cu-btn block bg-blue lg round">我是选手</button>
		</view>
    </view>
	
     
  </view>
</template>

<script>
  import { login } from '@/api/qiangda/user.js'

  export default {
	  
    data() {
      return {
        codeUrl: "",
		showModel:false,
        captchaEnabled: true,
        // 用户注册开关
        register: false,
        globalConfig: getApp().globalData.config,
        userInfo: {
          nickName: "",
          type: "",
        }
      }
    },
    created() {
    },
    methods: {
      // 用户选择身份
      chooseUserType(userType){
		  if(this.userInfo.nickName == "") {
			  // 弹框阻止
			  uni.showToast({title: '请输入昵称', 
							icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
			  				duration: 2000    //持续时间为 2秒
			  			})  
			  return
		  }
		  // 设置类型
		  this.userInfo.type = userType
		  login(this.userInfo).then(res=>{
			  
			  console.log(res, 'res');
			  
			  if(res.error) {
				  uni.showToast({title: res.error,icon: 'none',duration: 2000})  
				  return
			  } else {
				  this.userInfo = res.userInfo
				  
				  console.log('当前登录用户：' , this.userInfo)
				  // 跳转到 携带用户类型和用户id
				  this.$tab.navigateTo('/pages/qiangda/roomPage?userType=' + this.userInfo.type 
				  + "&userId="+ this.userInfo.id
				  + "&nickName="+ this.userInfo.nickName
				  )
			  }
		  })
		  
	  },
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }

  .normal-login-container {
    width: 100%;

    .logo-content {
      width: 100%;
      font-size: 21px;
      text-align: center;
      padding-top: 15%;

      image {
        border-radius: 4px;
      }

      .title {
        margin-left: 10px;
      }
    }

    .login-form-content {
      text-align: center;
      margin: 20px auto;
      margin-top: 15%;
      width: 80%;

      .input-item {
        margin: 20px auto;
        background-color: #f5f6f7;
        height: 45px;
        border-radius: 20px;

        .icon {
          font-size: 38rpx;
          margin-left: 10px;
          color: #999;
        }

        .input {
          width: 100%;
          font-size: 14px;
          line-height: 20px;
          text-align: left;
          padding-left: 15px;
        }

      }

      .login-btn {
        margin-top: 40px;
        height: 45px;
      }
      
      .reg {
        margin-top: 15px;
      }
      
      .xieyi {
        color: #333;
        margin-top: 20px;
      }
      
      .login-code {
        height: 38px;
        float: right;
      
        .login-code-img {
          height: 38px;
          position: absolute;
          margin-left: 10px;
          width: 200rpx;
        }
      }
    }
  }

</style>
